export default {
    getUrlKey(name) {
        return decodeURIComponent((new RegExp(`[?|&]${name}=` + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
    },
    // 阻止鼠标默认事件
    preventMouse() {
        window.document.oncontextmenu = function(e) {
            return false;
        };
    },
    // 时间戳
    timestamp() {
        return new Date().getTime()
    },

    getLocalTime(nS) {
        return new Date(parseInt(nS)).toLocaleString();
    },

    // 监听鼠标点击
    dbClick() {
        document.addEventListener('mousedown', (e) => {
            if (e.button == 2) {
                const obj = { x: e.clientX, y: e.clientY }
                return e.clientX
            }
        })
    },
    // 图片尺寸获取
    getImgSize(file) {
        return new Promise((resolve, reject) => {
            const reader = new FileReader()
            reader.readAsDataURL(file)
            reader.onload = function(theFile) {
                const image = new Image()
                image.src = theFile.target.result
                image.onload = function() {
                    resolve({
                        width: this.width,
                        height: this.height,
                    })
                }
            }
        })
    }
}